﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Search_RoomCatagory : System.Web.UI.Page
{
    private SqlDataReader sdr = null;
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            GridViewControl.ResetGridView(GridView1);
        }
        dt.Columns.Add("HM_RCategoryId");
        dt.Columns.Add("HM_RName");
        dt.Columns.Add("HM_RArea");
        dt.Columns.Add("HM_RBedNum");
        dt.Columns.Add("HM_RPrice");
        dt.Columns.Add("HM_RAirCondition");
        dt.Columns.Add("HM_RTV");
        GridViewControl.GridViewDataBind(GridView1, dt);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            if (DropDownList1.Text.Trim() == "一层")
            {
                String sql1 = "select * from HM_RoomCategory where HM_RCategoryId between 100 and 200";
                SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
                sdr = cmd.ExecuteReader();
                dt.Load(sdr);
                Command();
            }
            if (DropDownList1.Text.Trim() == "二层")
            {
                String sql1 = "select * from HM_RoomCategory where HM_RCategoryId between 200 and 300";
                SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
                sdr = cmd.ExecuteReader();
                dt.Load(sdr);
                Command();
            }
            if (DropDownList1.Text.Trim() == "三层")
            {
                String sql1 = "select * from HM_RoomCategory where HM_RCategoryId between 300 and 400";
                SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
                sdr = cmd.ExecuteReader();
                dt.Load(sdr);
                Command();
            }
            if (DropDownList1.Text.Trim() == "四层")
            {
                String sql1 = "select * from HM_RoomCategory where HM_RCategoryId between 400 and 500";
                SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
                sdr = cmd.ExecuteReader();
                dt.Load(sdr);
                Command();
            }
            if (DropDownList1.Text.Trim() == "五层")
            {
                String sql1 = "select * from HM_RoomCategory where HM_RCategoryId between 500 and 600";
                SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
                sdr = cmd.ExecuteReader();
                dt.Load(sdr);
                Command();
            }
            if (DropDownList1.Text.Trim() == "六层")
            {
                String sql1 = "select * from HM_RoomCategory where HM_RCategoryId between 600 and 700";
                SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
                sdr = cmd.ExecuteReader();
                dt.Load(sdr);
                Command();
            }
        }
        catch
        {
            Response.Write("<script>alert('查询失败，请查看相关信息！')</script>");
        }
        finally
        {
            sdr.Close();
        }
    }
    protected void Command()
    {
        try
        {
            if (dt.Rows.Count == 0)
            {
                int colnumcount = dt.Columns.Count;
                GridView1.Rows[0].Cells.Clear();
                GridView1.Rows[0].Cells.Add(new TableCell());
                GridView1.Rows[0].Cells[0].ColumnSpan = colnumcount;
                GridView1.Rows[0].Cells[0].Text = "相应楼层没有房间！";
                GridView1.Rows[0].Cells[0].Style.Add("color", "red");
                GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }
        catch
        {
            Response.Write("<script>alert('查询失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }

    }
}